﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FrameworkManapro.BusinessModel;
using FrameworkManapro.Utilities;
using FrameworkManapro.WebUI;

namespace GMAC.ReportingSystem.Business.Components
{
    public class AccountRepresentativeComponent : IBusinessComponent<Entities.AccountRepresentative>
    {
        private DataAccess.AccountRepresentativeDataAccess dac;

        public AccountRepresentativeComponent()
        {
            dac = new DataAccess.AccountRepresentativeDataAccess();
        }

        #region IBusinessComponent<AccountRepresentative> Members

        public int Create(Entities.AccountRepresentative entityToCreate)
        {
            if (Validate(entityToCreate))
            {
                var result = dac.Insert(entityToCreate);
                return result;
            }
            return 0;
        }

        public int Delete(Entities.AccountRepresentative entityToDelete)
        {
            if (entityToDelete.ID <= 0)
                throw new ArgumentOutOfRangeException("AccountRepresentativeID", "Value must be greater than zero.");

            return dac.Delete(entityToDelete);
        }

        public int Edit(Entities.AccountRepresentative entityToEdit)
        {
            if (entityToEdit.ID <= 0)
                throw new ArgumentOutOfRangeException("AccountRepresentativeID", "Value must be greater than zero.");

            return Validate(entityToEdit) ? dac.Update(entityToEdit) : 0;
        }

        public Entities.AccountRepresentative GetDetails(object entityId)
        {
            return dac.Get(entityId);
        }

        protected bool Validate(Entities.AccountRepresentative AccountRepresentative)
        {
            if (AccountRepresentative == null) throw new ArgumentNullException("AccountRepresentative", "The argument cannot be null.");
            if (string.IsNullOrEmpty(AccountRepresentative.ID.ToString())) throw new ArgumentNullException("ID", "The argument cannot be null.");
            if (string.IsNullOrEmpty(AccountRepresentative.FistName.ToString())) throw new ArgumentNullException("FistName", "The argument cannot be null.");
            if (string.IsNullOrEmpty(AccountRepresentative.LastName.ToString())) throw new ArgumentNullException("LastName", "The argument cannot be null.");
            if (string.IsNullOrEmpty(AccountRepresentative.IdentificationNumber)) throw new ArgumentNullException("IdentificationNumber", "The argument canno be null.");

            return true;
        }

        #endregion


        public Entities.AccountRepresentativeCollection GetList()
        {
            return dac.GetList();
        }

        public Entities.AccountRepresentativeCollection Search(string FirstName, string LastName, string IdentificationNumber, PagingDetails paging)
        {
            if (FirstName == null) FirstName = string.Empty;
            if (LastName == null) LastName = string.Empty;
            if (IdentificationNumber == null) IdentificationNumber = string.Empty;
            return dac.Search(FirstName, LastName, IdentificationNumber, paging);
        }



    }
}
